package com.exam.zhaohang;

import java.util.*;

/**
 * date:
 * description:
 */
public class Solution101 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        ArrayList<Integer> begin = new ArrayList<>();
        HashMap<Integer, Integer> indexMap = new HashMap<>();
        for (int i = 0; i < num; i++) {
            int number = scanner.nextInt();
            begin.add(number);
            indexMap.put(number, i);
        }
        ArrayList<Integer> end = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            end.add(scanner.nextInt());
        }
        int count = 0;
        int index = 0;
        boolean[] removed = new boolean[num];
        for (int i = 0; i < num; ) {
            if(removed[index]){
                index++;
                continue;
            }
            if(!Objects.equals(end.get(i), begin.get(index))) {
                count++;
                int pointer = indexMap.get(end.get(i));
                removed[pointer] = true;
            }else {
                index++;
            }
            i++;
        }
        System.out.println(count);

    }
}
